//
//  WBNetWorkManager.swift
//  SinaWB
//
//  Created by 财神软件 on 17/2/15.
//  Copyright © 2017年 财神软件. All rights reserved.
//

import UIKit
import AFNetworking

enum RequestType {
    case GET
    case POST
}

class WBNetWorkManager: AFHTTPSessionManager {
    
    /// 单利
    static let share = WBNetWorkManager()
    
    
    
    
    func request(type:RequestType ,urlStr:String ,params:[String:AnyObject] ,completion:@escaping (_ json:Any? ,_ issuccess:Bool)->()) -> () {
        let success = {(sectionTask:URLSessionDataTask ,json:Any?)->() in
            completion(json, true)
        }
        let failure = {(sectionTask:URLSessionDataTask? ,error:Error)->() in
            completion(nil, false)
        }
        
        if type == .GET {
            get(urlStr, parameters: params, progress: nil, success: success, failure: failure)
        }
        else{
            post(urlStr, parameters: params, progress: nil, success: success, failure: failure)
        }
    }
}
